import request from '@/utils/request';
import Qs from 'qs';

export function getOrgRoot() {
  return request({
    url: '/api/dood-organization/root',
    method: 'get',
  });
}

export function getOrgChildren(orgID) {
  return request({
    url: '/api/dood-organization/sons?orgId=' + orgID,
    method: 'get',
  });
}

export function getEmployee(data) {
  return request({
    url: '/contract/employeeQuery',
    method: 'post',
  });
}

// 获取所有用户列表
export function getDoodUser(data) {
  return request({
    url: '/api/user',
    method: 'get',
    params: data,
    paramsSerializer: (params) => {
      return Qs.stringify(params, { arrayFormat: 'repeat' });
    },
  });
}

// 获取排除指定角色的用户列表
export function getExcludeRolesDoodUser(data) {
  return request({
    url: '/api/user/exclude-roles',
    method: 'get',
    params: data,
    paramsSerializer: (params) => {
      return Qs.stringify(params, { arrayFormat: 'repeat' });
    },
  });
}

export function reloadDoodUser() {
  return request({
    url: '/api/dood-user/reload',
    method: 'post',
  });
}

export function reloadDoodDepartment() {
  return request({
    url: '/api/dood-organization/reload',
    method: 'post',
  });
}

export function getDoodFriends() {
  return request({
    url: '/api/dood-user/friends',
    method: 'get',
  });
}

export function getDoodOrg(orgID) {
  return request({
    url: '/api/dood-organization',
    method: 'get',
    params: { orgID },
    paramsSerializer: (params) => {
      return Qs.stringify(params, { arrayFormat: 'repeat' });
    },
  });
}
export function syncUser(type) {
  return request({
    url: `/api/user/sync?type=${type}`,
    method: 'get',
  });
}

export function syncOrganization(type) {
  return request({
    url: `/api/organization/sync?type=${type}`,
    method: 'get',
  });
}

export function getOrganization(data) {
  return request({
    url: '/api/thirdparties/organization',
    method: 'get',
    params: data,
  });
}

export default {
  getOrgRoot,
  getOrgChildren,
  getEmployee,
  getDoodUser,
  getExcludeRolesDoodUser,
  reloadDoodUser,
  reloadDoodDepartment,
  getDoodFriends,
  getDoodOrg,
  syncUser,
  syncOrganization,
  getOrganization,
};

